package com.lws.hellojmeter;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class WriteDB {

    private static final String DRIVER = "com.mysql.jdbc.Driver";
    private static final String URL = "jdbc:mysql://localhost:3306/test";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "root";

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName(DRIVER);
        Connection con = DriverManager.getConnection(URL, USERNAME, PASSWORD);

        con.setAutoCommit(false);
        Long startTime = System.currentTimeMillis();

        PreparedStatement pst = con.prepareStatement("insert into pet values (?,'中国')");
        for (int i = 0; i < 100; i++) {
            pst.setInt(1, i);
            pst.addBatch();
        }
        pst.executeBatch();
        con.commit();

        Long endTime = System.currentTimeMillis();
        System.out.println("用时：" + (endTime - startTime) / 1000);

        pst.close();
        con.close();
    }
}